package com.lzy.controller;

import com.lzy.base.BaseInfoProperties;
import com.lzy.utils.RedisOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("g")
@Slf4j
public class HelloController extends BaseInfoProperties {

    @Autowired
    private RedisOperator redis;

    @Autowired
    private DiscoveryClient discoveryClient;

    public void checkService() {
        List<ServiceInstance> instances = discoveryClient.getInstances("math-service");
        List<String> instanceslist = discoveryClient.getServices();
        log.info("Instances: {}", instances);
        log.info("services:{}",instanceslist);
    }

    @GetMapping("hello")
    public Object hello(){

        checkService();
        return "hello1~";
    }

    @GetMapping("setRedis")
    public Object hello(String k,String v){
        redis.set(k,v);
        return "hello redis~";
    }

    @GetMapping("getRedis")
    public Object hello(String k){

        return redis.get(k);
    }
}
